//
//  E7MenuLayer.cpp
//  E7_ENGINE
//
//  Created by cc on 12-3-2.
//  Copyright (c) 2012年 PalmGame. All rights reserved.
//

#include "E7MenuLayer.h"

#include "E7GameLayer.h"

#include "E7StageData.h"
#include "E7Logic.h"

CE7MenuLayer::CE7MenuLayer():
m_nFlag(-1),
m_bIsNormalAnimation(false)
{
    setIsTouchEnabled(true) ;

    if (IsPad())
    {
        CCSprite* pBack1 = CCSprite::spriteWithFile("back_menu1.png") ; // 513.
        pBack1->setAnchorPoint(ccp(0, 0)) ;
        pBack1->setPosition(ccp(0, 768-513)) ;
        addChild(pBack1) ;

//        s_pEffectManager->PlayEffect("menu_fire.plist", this) ;
        
        CCSprite* pBack2 = CCSprite::spriteWithFile("back_menu2.png") ; // 658.
        pBack2->setAnchorPoint(ccp(0, 0)) ;
        addChild(pBack2) ;

        //    m_pGameNameSprite = new CE7Sprite() ;
        //    m_pGameNameSprite->Init("gamename.png") ;
        //    addChild(m_pGameNameSprite) ;
        m_pGameName = new CE7AnimationGameName() ;
        m_pGameName->Init("gamename.png") ;
        addChild(m_pGameName) ;
        m_bIsAnimation = true ;
        
        m_pGameNameStrSprite = CCSprite::spriteWithFile("gamename_str.png") ;
        m_pGameNameStrSprite->setPosition(CCPointMake(522.0f, 650.0f)) ;
        m_pGameNameStrSprite->setOpacity(0) ;
        addChild(m_pGameNameStrSprite) ;
        m_pGameNameStr = new CE7AnimationSprite() ;
        m_pGameNameStr->Init(m_pGameNameStrSprite, ANI_SPRITE_ALPHA) ;
        addChild(m_pGameNameStr) ;
        
        m_pGameNameLightSprite = CCSprite::spriteWithFile("gamename_light.png") ;
        m_pGameNameLightSprite->setPosition(CCPointMake(522.0f, 720.0f)) ;
        m_pGameNameLightSprite->setOpacity(0) ;
        addChild(m_pGameNameLightSprite) ;
        m_pGameNameLight = new CE7AnimationSprite() ;
        m_pGameNameLight->Init(m_pGameNameLightSprite, ANI_SPRITE_ALPHA_LOOP) ;
        addChild(m_pGameNameLight) ;
        
        m_pButtonNormalBattle = CCMenuItemImage::itemFromNormalImage("button_normal_battle_n.png", 
                                                                     "button_normal_battle_s.png", 
                                                                     this, 
                                                                     menu_selector(CE7MenuLayer::ClickedNormalBattle)) ;
        m_pButtonCustomBattle = CCMenuItemImage::itemFromNormalImage("button_custom_battle_n.png", 
                                                                     "button_custom_battle_s.png", 
                                                                     "button_custom_battle_d.png",
                                                                     this, 
                                                                     menu_selector(CE7MenuLayer::ClickedCustomBattle)) ;
        m_pButtons = CCMenu::menuWithItems(m_pButtonNormalBattle, m_pButtonCustomBattle, NULL) ;
        //    m_pButtons = CCMenu::menuWithItems(m_pButtonNormalBattle, m_pButtonCollectibleBattle, m_pButtonCustomBattle, NULL) ;
        
        float init_x = -15.0f ;
        float init_y = -310.0f ;
        //    float offset_x = 315.0f ;
        float offset_x = 200.0f ;
        m_pButtonNormalBattle->setPosition(ccp(init_x-offset_x, init_y)) ;
        //    m_pButtonCollectibleBattle->setPosition(ccp(init_x, init_y)) ;
        m_pButtonCustomBattle->setPosition(ccp(init_x+offset_x, init_y)) ;
        m_pButtonCustomBattle->setIsEnabled(false) ;
        addChild(m_pButtons) ;
        
        m_pNormal = new CE7AnimationSprite() ;
        m_pButtonNormalBattle->setIsVisible(false) ;
        m_pNormal->Init(m_pButtonNormalBattle, ANI_SPRITE_SCALE) ;
        //    pNormal->Start() ;
        addChild(m_pNormal) ;
        
        m_pCustom = new CE7AnimationSprite() ;
        m_pButtonCustomBattle->setIsVisible(false) ;
        m_pCustom->Init(m_pButtonCustomBattle, ANI_SPRITE_SCALE) ;
        //    pCustom->Start() ;
        addChild(m_pCustom) ;
        
        m_pCustomLayer = new CCLayer() ;
        m_pCustomLayer->setIsTouchEnabled(false) ;
        m_pCustomLayer->setIsVisible(false) ;
        addChild(m_pCustomLayer) ;
        
        m_pNormalLayer = new CCLayer() ;
        m_pNormalLayer->setIsTouchEnabled(false) ;
        m_pNormalLayer->setIsVisible(false) ;
        addChild(m_pNormalLayer) ;
        
        float percent = (float)CE7StageData::GetStageData()->GetCompleteCount() / (float)STAGE_COUNT ;
        m_pActiveCustomSprite = CCSprite::spriteWithFile("button_custom_battle_n.png") ;
        m_pActiveCustomSprite->setAnchorPoint(CCPointZero) ;
        m_pActiveCustomSprite->setPosition(CCPointMake(623.0f-74.0f, 74.0f-27.0f)) ;
        m_pActiveCustomSprite->setTextureRect(CCRectMake(0, 0, percent*296, 54)) ;
        m_pActiveCustomSprite->setIsVisible(false) ;
        addChild(m_pActiveCustomSprite) ;
        
        if (CE7StageData::GetStageData()->GetCompleteCount() >= STAGE_COUNT)
        {
            m_pButtonCustomBattle->setIsEnabled(true) ;
        }

        m_pGameName->Start() ;
    }
    else
    {
        CCSprite* pBack1 = CCSprite::spriteWithFile("back_menu1_iphone.png") ; // 513.
        pBack1->setAnchorPoint(ccp(0, 0)) ;
        pBack1->setPosition(ccp(0, 640-513)) ;
        addChild(pBack1) ;
        
//        s_pEffectManager->PlayEffect("menu_fire_iphone.plist", this) ;
        
        CCSprite* pBack2 = CCSprite::spriteWithFile("back_menu2_iphone.png") ; // 658.
        pBack2->setAnchorPoint(ccp(0, 0)) ;
        addChild(pBack2) ;

        //    m_pGameNameSprite = new CE7Sprite() ;
        //    m_pGameNameSprite->Init("gamename.png") ;
        //    addChild(m_pGameNameSprite) ;
        m_pGameName = new CE7AnimationGameName() ;
        m_pGameName->Init("gamename_iphone.png") ;
        m_pGameName->Start() ;
        addChild(m_pGameName) ;
        m_bIsAnimation = true ;
        
        m_pGameNameStrSprite = CCSprite::spriteWithFile("gamename_str_iphone.png") ;
        m_pGameNameStrSprite->setPosition(CCPointMake(522.0f/2-30.0f, 650.0f/2-80.0f)) ;
        m_pGameNameStrSprite->setOpacity(0) ;
        addChild(m_pGameNameStrSprite) ;
        m_pGameNameStr = new CE7AnimationSprite() ;
        m_pGameNameStr->Init(m_pGameNameStrSprite, ANI_SPRITE_ALPHA) ;
        addChild(m_pGameNameStr) ;
        
        m_pGameNameLightSprite = CCSprite::spriteWithFile("gamename_light_iphone.png") ;
        m_pGameNameLightSprite->setPosition(CCPointMake(522.0f/2-30.0f, 720.0f/2-80.0f)) ;
        m_pGameNameLightSprite->setOpacity(0) ;
        addChild(m_pGameNameLightSprite) ;
        m_pGameNameLight = new CE7AnimationSprite() ;
        m_pGameNameLight->Init(m_pGameNameLightSprite, ANI_SPRITE_ALPHA_LOOP) ;
        addChild(m_pGameNameLight) ;
        
        m_pButtonNormalBattle = CCMenuItemImage::itemFromNormalImage("button_normal_battle_n_iphone.png", 
                                                                     "button_normal_battle_s_iphone.png", 
                                                                     this, 
                                                                     menu_selector(CE7MenuLayer::ClickedNormalBattle)) ;
        m_pButtonCustomBattle = CCMenuItemImage::itemFromNormalImage("button_custom_battle_n_iphone.png", 
                                                                     "button_custom_battle_s_iphone.png", 
                                                                     "button_custom_battle_d_iphone.png",
                                                                     this, 
                                                                     menu_selector(CE7MenuLayer::ClickedCustomBattle)) ;
        m_pButtons = CCMenu::menuWithItems(m_pButtonNormalBattle, m_pButtonCustomBattle, NULL) ;
        //    m_pButtons = CCMenu::menuWithItems(m_pButtonNormalBattle, m_pButtonCollectibleBattle, m_pButtonCustomBattle, NULL) ;
        
        float init_x = -15.0f ;
        float init_y = -310.0f/2+40.0f ;
        //    float offset_x = 315.0f ;
        float offset_x = 200.0f/2 ;
        m_pButtonNormalBattle->setPosition(ccp(init_x-offset_x, init_y)) ;
        //    m_pButtonCollectibleBattle->setPosition(ccp(init_x, init_y)) ;
        m_pButtonCustomBattle->setPosition(ccp(init_x+offset_x, init_y)) ;
        m_pButtonCustomBattle->setIsEnabled(false) ;
        addChild(m_pButtons) ;
        
        m_pNormal = new CE7AnimationSprite() ;
        m_pButtonNormalBattle->setIsVisible(false) ;
        m_pNormal->Init(m_pButtonNormalBattle, ANI_SPRITE_SCALE) ;
        //    pNormal->Start() ;
        addChild(m_pNormal) ;
        
        m_pCustom = new CE7AnimationSprite() ;
        m_pButtonCustomBattle->setIsVisible(false) ;
        m_pCustom->Init(m_pButtonCustomBattle, ANI_SPRITE_SCALE) ;
        //    pCustom->Start() ;
        addChild(m_pCustom) ;
        
        m_pCustomLayer = new CCLayer() ;
        m_pCustomLayer->setIsTouchEnabled(false) ;
        m_pCustomLayer->setIsVisible(false) ;
        addChild(m_pCustomLayer) ;
        
        m_pNormalLayer = new CCLayer() ;
        m_pNormalLayer->setIsTouchEnabled(false) ;
        m_pNormalLayer->setIsVisible(false) ;
        addChild(m_pNormalLayer) ;
        
        float percent = (float)CE7StageData::GetStageData()->GetCompleteCount() / (float)STAGE_COUNT ;
        m_pActiveCustomSprite = CCSprite::spriteWithFile("button_custom_battle_n_iphone.png") ;
        m_pActiveCustomSprite->setAnchorPoint(CCPointZero) ;
        m_pActiveCustomSprite->setPosition(CCPointMake((623.0f-74.0f)/2-24.0f, (74.0f-27.0f)/2+8.0f)) ;
        m_pActiveCustomSprite->setTextureRect(CCRectMake(0, 0, percent*148, 27)) ;
//        m_pActiveCustomSprite->setOpacity(100.0f) ;
        m_pActiveCustomSprite->setIsVisible(false) ;
        addChild(m_pActiveCustomSprite) ;
        
        if (CE7StageData::GetStageData()->GetCompleteCount() >= STAGE_COUNT)
        {
            m_pButtonCustomBattle->setIsEnabled(true) ;
        }
    }
}

CE7MenuLayer::CE7MenuLayer(int flag)
{
    m_nFlag = 0 ;
//    m_bIsAnimation = false ;
    m_bIsNormalAnimation = false ;

    setIsTouchEnabled(true) ;
    
    if (IsPad())
    {
        CCSprite* pBack1 = CCSprite::spriteWithFile("back_menu1.png") ; // 513.
        pBack1->setAnchorPoint(ccp(0, 0)) ;
        pBack1->setPosition(ccp(0, 768-513)) ;
        addChild(pBack1) ;

//        s_pEffectManager->PlayEffect("menu_fire.plist", this) ;
        
        CCSprite* pBack2 = CCSprite::spriteWithFile("back_menu2.png") ; // 658.
        pBack2->setAnchorPoint(ccp(0, 0)) ;
        addChild(pBack2) ;
        
        m_pGameNameSprite = new CE7Sprite() ;
        m_pGameNameSprite->Init("gamename.png") ;
        m_pGameNameSprite->setPosition(CCPointMake(522.0f, 650.0f)) ;
        addChild(m_pGameNameSprite) ;
        
        m_pGameNameStrSprite = CCSprite::spriteWithFile("gamename_str.png") ;
        m_pGameNameStrSprite->setPosition(CCPointMake(522.0f, 650.0f)) ;
        addChild(m_pGameNameStrSprite) ;
        
        m_pGameNameLightSprite = CCSprite::spriteWithFile("gamename_light.png") ;
        m_pGameNameLightSprite->setPosition(CCPointMake(522.0f, 720.0f)) ;
        m_pGameNameLightSprite->setOpacity(0) ;
        addChild(m_pGameNameLightSprite) ;
        m_pGameNameLight = new CE7AnimationSprite() ;
        m_pGameNameLight->Init(m_pGameNameLightSprite, ANI_SPRITE_ALPHA_LOOP) ;
        addChild(m_pGameNameLight) ;
        
        m_pButtonNormalBattle = CCMenuItemImage::itemFromNormalImage("button_normal_battle_n.png", 
                                                                     "button_normal_battle_s.png", 
                                                                     this, 
                                                                     menu_selector(CE7MenuLayer::ClickedNormalBattle)) ;
        m_pButtonCustomBattle = CCMenuItemImage::itemFromNormalImage("button_custom_battle_n.png", 
                                                                     "button_custom_battle_s.png", 
                                                                     "button_custom_battle_d.png",
                                                                     this, 
                                                                     menu_selector(CE7MenuLayer::ClickedCustomBattle)) ;
        m_pButtons = CCMenu::menuWithItems(m_pButtonNormalBattle, m_pButtonCustomBattle, NULL) ;
        //    m_pButtons = CCMenu::menuWithItems(m_pButtonNormalBattle, m_pButtonCollectibleBattle, m_pButtonCustomBattle, NULL) ;
        
        float init_x = -15.0f ;
        float init_y = -310.0f ;
        //    float offset_x = 315.0f ;
        float offset_x = 200.0f ;
        m_pButtonNormalBattle->setPosition(ccp(init_x-offset_x, init_y)) ;
        //    m_pButtonCollectibleBattle->setPosition(ccp(init_x, init_y)) ;
        m_pButtonCustomBattle->setPosition(ccp(init_x+offset_x, init_y)) ;
        m_pButtonCustomBattle->setIsEnabled(false) ;
        addChild(m_pButtons) ;
        
        m_pCustomLayer = new CCLayer() ;
        m_pCustomLayer->setIsTouchEnabled(false) ;
        m_pCustomLayer->setIsVisible(false) ;
        addChild(m_pCustomLayer) ;
        
        m_pNormalLayer = new CCLayer() ;
        m_pNormalLayer->setIsTouchEnabled(false) ;
        m_pNormalLayer->setIsVisible(false) ;
        addChild(m_pNormalLayer) ;
        
        float percent = (float)CE7StageData::GetStageData()->GetCompleteCount() / (float)STAGE_COUNT ;
        m_pActiveCustomSprite = CCSprite::spriteWithFile("button_custom_battle_n.png") ;
        m_pActiveCustomSprite->setAnchorPoint(CCPointZero) ;
        m_pActiveCustomSprite->setPosition(CCPointMake(623.0f-74.0f, 74.0f-27.0f)) ;
        m_pActiveCustomSprite->setTextureRect(CCRectMake(0, 0, percent*296, 54)) ;
        m_pActiveCustomSprite->setIsVisible(false) ;
        addChild(m_pActiveCustomSprite) ;
        
        if (CE7StageData::GetStageData()->GetCompleteCount() >= STAGE_COUNT)
        {
            m_pButtonCustomBattle->setIsEnabled(true) ;
        }
    }
    else
    {
        CCSprite* pBack1 = CCSprite::spriteWithFile("back_menu1_iphone.png") ; // 513.
        pBack1->setAnchorPoint(ccp(0, 0)) ;
        pBack1->setPosition(ccp(0, 640-513)) ;
        addChild(pBack1) ;
        
//        s_pEffectManager->PlayEffect("menu_fire_iphone.plist", this) ;
        
        CCSprite* pBack2 = CCSprite::spriteWithFile("back_menu2_iphone.png") ; // 658.
        pBack2->setAnchorPoint(ccp(0, 0)) ;
        addChild(pBack2) ;
        
        m_pGameNameSprite = new CE7Sprite() ;
        m_pGameNameSprite->Init("gamename_iphone.png") ;
        m_pGameNameSprite->setPosition(CCPointMake(522.0f/2-30.0f, 650.0f/2-80.0f)) ;
        addChild(m_pGameNameSprite) ;
        
        m_pGameNameStrSprite = CCSprite::spriteWithFile("gamename_str_iphone.png") ;
        m_pGameNameStrSprite->setPosition(CCPointMake(522.0f/2-30.0f, 650.0f/2-80.0f)) ;
        addChild(m_pGameNameStrSprite) ;
        
        m_pGameNameLightSprite = CCSprite::spriteWithFile("gamename_light_iphone.png") ;
        m_pGameNameLightSprite->setPosition(CCPointMake(522.0f/2-30.0f, 720.0f/2-80.0f)) ;
        m_pGameNameLightSprite->setOpacity(0) ;
        addChild(m_pGameNameLightSprite) ;
        m_pGameNameLight = new CE7AnimationSprite() ;
        m_pGameNameLight->Init(m_pGameNameLightSprite, ANI_SPRITE_ALPHA_LOOP) ;
        addChild(m_pGameNameLight) ;
        
        m_pButtonNormalBattle = CCMenuItemImage::itemFromNormalImage("button_normal_battle_n_iphone.png", 
                                                                     "button_normal_battle_s_iphone.png", 
                                                                     this, 
                                                                     menu_selector(CE7MenuLayer::ClickedNormalBattle)) ;
        m_pButtonCustomBattle = CCMenuItemImage::itemFromNormalImage("button_custom_battle_n_iphone.png", 
                                                                     "button_custom_battle_s_iphone.png", 
                                                                     "button_custom_battle_d_iphone.png",
                                                                     this, 
                                                                     menu_selector(CE7MenuLayer::ClickedCustomBattle)) ;
        m_pButtons = CCMenu::menuWithItems(m_pButtonNormalBattle, m_pButtonCustomBattle, NULL) ;
        //    m_pButtons = CCMenu::menuWithItems(m_pButtonNormalBattle, m_pButtonCollectibleBattle, m_pButtonCustomBattle, NULL) ;
        
        float init_x = -15.0f ;
        float init_y = -310.0f/2+40.0f ;
        //    float offset_x = 315.0f ;
        float offset_x = 200.0f/2 ;
        m_pButtonNormalBattle->setPosition(ccp(init_x-offset_x, init_y)) ;
        //    m_pButtonCollectibleBattle->setPosition(ccp(init_x, init_y)) ;
        m_pButtonCustomBattle->setPosition(ccp(init_x+offset_x, init_y)) ;
        m_pButtonCustomBattle->setIsEnabled(false) ;
        addChild(m_pButtons) ;
        
        m_pCustomLayer = new CCLayer() ;
        m_pCustomLayer->setIsTouchEnabled(false) ;
        m_pCustomLayer->setIsVisible(false) ;
        addChild(m_pCustomLayer) ;
        
        m_pNormalLayer = new CCLayer() ;
        m_pNormalLayer->setIsTouchEnabled(false) ;
        m_pNormalLayer->setIsVisible(false) ;
        addChild(m_pNormalLayer) ;
        
        float percent = (float)CE7StageData::GetStageData()->GetCompleteCount() / (float)STAGE_COUNT ;
        m_pActiveCustomSprite = CCSprite::spriteWithFile("button_custom_battle_n_iphone.png") ;
        m_pActiveCustomSprite->setAnchorPoint(CCPointZero) ;
        m_pActiveCustomSprite->setPosition(CCPointMake((623.0f-74.0f)/2-24.0f, (74.0f-27.0f)/2+8.0f)) ;
        m_pActiveCustomSprite->setTextureRect(CCRectMake(0, 0, percent*148, 27)) ;
        m_pActiveCustomSprite->setIsVisible(false) ;
        addChild(m_pActiveCustomSprite) ;
        
        if (CE7StageData::GetStageData()->GetCompleteCount() >= STAGE_COUNT)
        {
            m_pButtonCustomBattle->setIsEnabled(true) ;
        }
    }
}

CE7MenuLayer::~CE7MenuLayer()
{
//    SAFE_DELETE(m_pGameName) ;
//    SAFE_DELETE(m_pGameNameStr) ;
//    SAFE_DELETE(m_pNormal) ;
//    SAFE_DELETE(m_pCustom) ;

//    SAFE_RELEASE(m_pSelMapBackSprite) ;
//    SAFE_RELEASE(m_pMapSizeSprite) ;
//    SAFE_RELEASE(m_pSelMapSprite) ;
}

void CE7MenuLayer::ClickedNormalBattle()
{
    if (s_bPlaySound)
    {
        SimpleAudioEngine::sharedEngine()->playEffect(sound_button) ;
    }

    if (m_bIsAnimation)
    {
        return ;
    }

    InitNormalData() ;
}

void CE7MenuLayer::ClickedCustomBattle()
{
    if (s_bPlaySound)
    {
        SimpleAudioEngine::sharedEngine()->playEffect(sound_button) ;
    }

    if (m_bIsAnimation)
    {
        return ;
    }

    InitCustomData() ;
}

bool CE7MenuLayer::Loop()
{
    if (LS_STOP == GetStep())
    {
        return false ;
    }

    if (0 == m_nFlag)
    {
        m_nFlag = 1 ;
        m_bIsAnimation = false ;
        m_pGameNameLight->Start() ;
        if (CE7StageData::GetStageData()->GetCompleteCount() < STAGE_COUNT)
        {
            m_pButtonCustomBattle->setIsEnabled(false) ;
            m_pActiveCustomSprite->setIsVisible(true) ;
        }
        else
        {
            m_pButtonCustomBattle->setIsEnabled(true) ;
            m_pActiveCustomSprite->setIsVisible(false) ;
        }

        return true ;
    }

    if (!m_bIsAnimation && !m_bIsNormalAnimation)
    {
//        printf("step -------- 3 \n") ;
        return true ;
    }

    if (m_bIsNormalAnimation)
    {
        return true ;
    }

    if (0 < m_nFlag)
    {
        return true ;
    }

    if (NULL != m_pGameName)
    {
//        printf("step -------- 0 \n") ;
        if (!m_pGameName->IsPlaying())
        {
//            printf("step -------- 0 - 1 \n") ;
            m_pGameName = NULL ;
            m_pGameNameStr->Start() ;
            return true ;
        }
    }
    else if (NULL == m_pGameName)
    {
//        printf("step -------- 1 \n") ;
        if (NULL != m_pGameNameStr && !m_pGameNameStr->IsPlaying())
        {
//            printf("step -------- 1 - 1 \n") ;
            m_pGameNameStr = NULL ;
            m_pGameNameLight->Start() ;
            m_pNormal->Start() ;
            m_pCustom->Start() ;
            return true ;
        }
        else if (NULL == m_pGameNameStr)
        {
//            printf("step -------- 1 - 2 \n") ;
            if (NULL != m_pNormal && !m_pNormal->IsPlaying())
            {
//                printf("step -------- 1 - 2 - 1 \n") ;
                m_bIsAnimation = false ;
                if (CE7StageData::GetStageData()->GetCompleteCount() < STAGE_COUNT)
                {
                    m_pButtonCustomBattle->setIsEnabled(false) ;
                    m_pActiveCustomSprite->setIsVisible(true) ;
                }
                else
                {
                    m_pButtonCustomBattle->setIsEnabled(true) ;
                    m_pActiveCustomSprite->setIsVisible(false) ;
                }
            }
        }
//        printf("step -------- 1 - 3 \n") ;
    }
    
//    printf("step -------- 2 \n") ;
    return true ;
}

void CE7MenuLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
}

void CE7MenuLayer::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
{
}

void CE7MenuLayer::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent)
{
}

void CE7MenuLayer::ccTouchesCancelled(CCSet *pTouches, CCEvent *pEvent)
{
    printf("CE7MenuLayer::ccTouchesCancelled\n") ;
}

void CE7MenuLayer::InitCustomData()
{
    m_nGameLayerTag = 100 ;
    
    if (IsPad())
    {
        float init_x = 332 ;
        float init_y = 254-80 ;
        m_nSelIndex = 0 ;
        
        for (int i = 0; i < 3; ++i)
        {
            m_posSelMap[i] = ccp(init_x + i * 180, init_y) ;
        }

        m_pSelMapBackSprite = new CE7Sprite() ;
        m_pSelMapBackSprite->Init("back_dialog_select_map.png") ;
        m_pSelMapBackSprite->setPosition(CCPointMake(512.0f, 304.0f)) ;
        m_pCustomLayer->addChild(m_pSelMapBackSprite) ;
        
        m_pMapSizeSprite = new CE7Sprite() ;
        m_pMapSizeSprite->Init("label_mapsize.png") ;
        m_pMapSizeSprite->setPosition(ccp(m_pMapSizeSprite->getPosition().x, m_pMapSizeSprite->getPosition().y-40)) ;
        m_pCustomLayer->addChild(m_pMapSizeSprite) ;
        
        m_pButtonFrame[0] = CCMenuItemImage::itemFromNormalImage("flag_select_frame.png", "flag_select_frame.png",
                                                                 this, menu_selector(CE7MenuLayer::ClickedSelectMap_0)) ;
        m_pButtonFrame[1] = CCMenuItemImage::itemFromNormalImage("flag_select_frame.png", "flag_select_frame.png",
                                                                 this, menu_selector(CE7MenuLayer::ClickedSelectMap_1)) ;
        m_pButtonFrame[2] = CCMenuItemImage::itemFromNormalImage("flag_select_frame.png", "flag_select_frame.png",
                                                                 this, menu_selector(CE7MenuLayer::ClickedSelectMap_2)) ;
        
        m_pButtonGenerate = CCMenuItemImage::itemFromNormalImage("button_generate_n.png", "button_generate_s.png",
                                                                 this, menu_selector(CE7MenuLayer::ClickedCustomGenerate)) ;
        m_pButtonOK = CCMenuItemImage::itemFromNormalImage("button_ok_n.png", "button_ok_s.png",
                                                           this, menu_selector(CE7MenuLayer::ClickedCustomStartGame)) ;
        m_pButtonAgain = CCMenuItemImage::itemFromNormalImage("button_again_n.png", "button_again_s.png",
                                                              this, menu_selector(CE7MenuLayer::ClickedCustomAgain)) ;
        
        CCSprite* pNormalClose = CCSprite::spriteWithFile("close.png") ;
        CCSprite* pSelectClose = CCSprite::spriteWithFile("close.png") ;
        pSelectClose->setColor(ccc3(1, 1, 1)) ;
        m_pButtonClose = CCMenuItemImage::itemFromNormalSprite(pNormalClose, pSelectClose, this, menu_selector(CE7MenuLayer::ClickedCustomClose)) ;
        
        float offset_x = 512 ;
        float offset_y = 384 ;
        for (int i = 0; i < 3; ++i)
        {
            m_pButtonFrame[i]->setPosition(ccp(m_posSelMap[i].x-offset_x, m_posSelMap[i].y-offset_y)) ;
        }
        m_pButtonGenerate->setPosition(ccp(m_posSelMap[1].x-offset_x, m_posSelMap[1].y-offset_y-72)) ;
        m_pButtonGenerate->setIsVisible(true) ;
        
        m_pButtonOK->setPosition(ccp(m_posSelMap[1].x-offset_x-130, m_posSelMap[1].y-offset_y-72)) ;
        m_pButtonOK->setIsVisible(false) ;
        m_pButtonAgain->setPosition(ccp(m_posSelMap[1].x-offset_x+130, m_posSelMap[1].y-offset_y-72)) ;
        m_pButtonAgain->setIsVisible(false) ;
        
        m_pButtonClose->setPosition(ccp(m_posSelMap[1].x-offset_x+305, m_posSelMap[1].y-50)) ;
        
        m_pDialogButtons = CCMenu::menuWithItems(m_pButtonFrame[0], m_pButtonFrame[1], m_pButtonFrame[2],
                                                 m_pButtonGenerate, m_pButtonOK, m_pButtonAgain, m_pButtonClose, NULL) ;
        m_pCustomLayer->addChild(m_pDialogButtons) ;
        
        m_pSelMapSprite = new CE7Sprite() ;
        m_pSelMapSprite->Init("flag_select.png") ;
        m_pSelMapSprite->setPosition(m_posSelMap[m_nSelIndex]) ;
        m_pCustomLayer->addChild(m_pSelMapSprite) ;
    }
    else
    {
        float init_x = 332/2 - 15.0f ;
        float init_y = (254-80)/2+30 ;
        m_nSelIndex = 0 ;
        
        for (int i = 0; i < 3; ++i)
        {
            m_posSelMap[i] = ccp(init_x + i * 85, init_y) ;
        }

        m_pSelMapBackSprite = new CE7Sprite() ;
        m_pSelMapBackSprite->Init("back_dialog_select_map_iphone.png") ;
        m_pSelMapBackSprite->setPosition(CCPointMake(512.0f/2-15.0f, 304.0f/2)) ;
        m_pCustomLayer->addChild(m_pSelMapBackSprite) ;
        
        m_pMapSizeSprite = new CE7Sprite() ;
        m_pMapSizeSprite->Init("label_mapsize_iphone.png") ;
        m_pMapSizeSprite->setPosition(ccp(m_pMapSizeSprite->getPosition().x, m_pMapSizeSprite->getPosition().y)) ;
        m_pCustomLayer->addChild(m_pMapSizeSprite) ;
        
        m_pButtonFrame[0] = CCMenuItemImage::itemFromNormalImage("flag_select_frame_iphone.png",
                                                                 "flag_select_frame_iphone.png",
                                                                 this, menu_selector(CE7MenuLayer::ClickedSelectMap_0)) ;
        m_pButtonFrame[1] = CCMenuItemImage::itemFromNormalImage("flag_select_frame_iphone.png",
                                                                 "flag_select_frame_iphone.png",
                                                                 this, menu_selector(CE7MenuLayer::ClickedSelectMap_1)) ;
        m_pButtonFrame[2] = CCMenuItemImage::itemFromNormalImage("flag_select_frame_iphone.png",
                                                                 "flag_select_frame_iphone.png",
                                                                 this, menu_selector(CE7MenuLayer::ClickedSelectMap_2)) ;
        
        m_pButtonGenerate = CCMenuItemImage::itemFromNormalImage("button_generate_n_iphone.png",
                                                                 "button_generate_s_iphone.png",
                                                                 this, menu_selector(CE7MenuLayer::ClickedCustomGenerate)) ;
        m_pButtonOK = CCMenuItemImage::itemFromNormalImage("button_ok_n_iphone.png",
                                                           "button_ok_s_iphone.png",
                                                           this, menu_selector(CE7MenuLayer::ClickedCustomStartGame)) ;
        m_pButtonAgain = CCMenuItemImage::itemFromNormalImage("button_again_n_iphone.png",
                                                              "button_again_s_iphone.png",
                                                              this, menu_selector(CE7MenuLayer::ClickedCustomAgain)) ;
        
        CCSprite* pNormalClose = CCSprite::spriteWithFile("close_iphone.png") ;
        CCSprite* pSelectClose = CCSprite::spriteWithFile("close_iphone.png") ;
        pSelectClose->setColor(ccc3(1, 1, 1)) ;
        m_pButtonClose = CCMenuItemImage::itemFromNormalSprite(pNormalClose, pSelectClose, this, menu_selector(CE7MenuLayer::ClickedCustomClose)) ;
        
        float offset_x = 240 ;
        float offset_y = 192 ;
        for (int i = 0; i < 3; ++i)
        {
            m_pButtonFrame[i]->setPosition(ccp(m_posSelMap[i].x-offset_x, m_posSelMap[i].y-offset_y)) ;
        }
        m_pButtonGenerate->setPosition(ccp(m_posSelMap[1].x-offset_x, m_posSelMap[1].y-offset_y-72/2)) ;
        m_pButtonGenerate->setIsVisible(true) ;

        m_pButtonOK->setPosition(ccp(m_posSelMap[1].x-offset_x-130/2, m_posSelMap[1].y-offset_y-72/2)) ;
        m_pButtonOK->setIsVisible(false) ;
        m_pButtonAgain->setPosition(ccp(m_posSelMap[1].x-offset_x+130/2, m_posSelMap[1].y-offset_y-72/2)) ;
        m_pButtonAgain->setIsVisible(false) ;
        
        m_pButtonClose->setPosition(ccp(m_posSelMap[1].x-offset_x+305/2+5, m_posSelMap[1].y-50/2+3)) ;
        
        m_pDialogButtons = CCMenu::menuWithItems(m_pButtonFrame[0], m_pButtonFrame[1], m_pButtonFrame[2],
                                                 m_pButtonGenerate, m_pButtonOK, m_pButtonAgain, m_pButtonClose, NULL) ;
        m_pCustomLayer->addChild(m_pDialogButtons) ;
        
        m_pSelMapSprite = new CE7Sprite() ;
        m_pSelMapSprite->Init("flag_select_iphone.png") ;
        m_pSelMapSprite->setPosition(CCPointMake(m_posSelMap[m_nSelIndex].x, m_posSelMap[m_nSelIndex].y-30.0f)) ;
        m_pCustomLayer->addChild(m_pSelMapSprite) ;
    }

    m_pButtonNormalBattle->setIsVisible(false) ;
    m_pButtonCustomBattle->setIsVisible(false) ;
    m_pActiveCustomSprite->setIsVisible(false) ;
    m_pCustomLayer->setIsVisible(true) ;
}

void CE7MenuLayer::ClickedSelectMap_0()
{
    if (s_bPlaySound)
    {
        SimpleAudioEngine::sharedEngine()->playEffect(sound_button) ;
    }

    m_nSelIndex = 0 ;
    if (IsPad())
    {
        m_pSelMapSprite->setPosition(m_posSelMap[m_nSelIndex]) ;
    }
    else
    {
        m_pSelMapSprite->setPosition(CCPointMake(m_posSelMap[m_nSelIndex].x, m_posSelMap[m_nSelIndex].y-30.0f)) ;
    }
}

void CE7MenuLayer::ClickedSelectMap_1()
{
    if (s_bPlaySound)
    {
        SimpleAudioEngine::sharedEngine()->playEffect(sound_button) ;
    }

    m_nSelIndex = 1 ;
    if (IsPad())
    {
        m_pSelMapSprite->setPosition(m_posSelMap[m_nSelIndex]) ;
    }
    else
    {
        m_pSelMapSprite->setPosition(CCPointMake(m_posSelMap[m_nSelIndex].x, m_posSelMap[m_nSelIndex].y-30.0f)) ;
    }
}

void CE7MenuLayer::ClickedSelectMap_2()
{
    if (s_bPlaySound)
    {
        SimpleAudioEngine::sharedEngine()->playEffect(sound_button) ;
    }

    m_nSelIndex = 2 ;
    if (IsPad())
    {
        m_pSelMapSprite->setPosition(m_posSelMap[m_nSelIndex]) ;
    }
    else
    {
        m_pSelMapSprite->setPosition(CCPointMake(m_posSelMap[m_nSelIndex].x, m_posSelMap[m_nSelIndex].y-30.0f)) ;
    }
}

void CE7MenuLayer::ClickedCustomGenerate()
{
    if (s_bPlaySound)
    {
        SimpleAudioEngine::sharedEngine()->playEffect(sound_button) ;
    }

    s_pLogic->SetGameMode(1) ;
    s_pLogic->SetCustomMapID(m_nSelIndex) ;

    // hide other buttons.
    m_pMapSizeSprite->setIsVisible(false) ;
    m_pSelMapSprite->setIsVisible(false) ;
    for (int i = 0; i < 3; ++i)
    {
        m_pButtonFrame[i]->setIsVisible(false) ;
    }
    m_pButtonGenerate->setIsVisible(false) ;
    //////////////////////////////////////
    m_pButtonOK->setIsVisible(true) ;
    m_pButtonAgain->setIsVisible(true) ;
    
    // create map loading . . .
    if (NULL == s_pGameLayer)
    {
        s_pGameLayer = new CE7GameLayer() ;
    }
    s_pGameLayer->SetPreviewMode() ;
    m_pCustomLayer->addChild(s_pGameLayer, m_nGameLayerTag, m_nGameLayerTag) ;
}

void CE7MenuLayer::ClickedCustomStartGame()
{
    if (s_bPlaySound)
    {
        SimpleAudioEngine::sharedEngine()->playEffect(sound_button) ;
    }

    m_pCustomLayer->removeChildByTag(m_nGameLayerTag, false) ;
    SetStep(LS_STOP) ;
}

void CE7MenuLayer::ClickedCustomAgain()
{
    if (s_bPlaySound)
    {
        SimpleAudioEngine::sharedEngine()->playEffect(sound_button) ;
    }

    if (NULL != s_pGameLayer)
    {
        m_pCustomLayer->removeChildByTag(m_nGameLayerTag, true) ;
    }
    s_pGameLayer = new CE7GameLayer() ;
    s_pGameLayer->SetPreviewMode() ;
    m_pCustomLayer->addChild(s_pGameLayer, m_nGameLayerTag, m_nGameLayerTag) ;
}

void CE7MenuLayer::ClickedCustomClose()
{
    if (s_bPlaySound)
    {
        SimpleAudioEngine::sharedEngine()->playEffect(sound_button) ;
    }

    m_pCustomLayer->removeAllChildrenWithCleanup(false) ;
    m_pCustomLayer->setIsVisible(false) ;

    m_pButtonNormalBattle->setIsVisible(true) ;
    m_pButtonCustomBattle->setIsVisible(true) ;
    m_pActiveCustomSprite->setIsVisible(false) ;
}

// normal battle.
void CE7MenuLayer::InitNormalData()
{
    if (IsPad())
    {
        float init_x = 332 ;
        float init_y = 254-80 ;

        m_pBackNormalSprite = new CE7Sprite() ;
        m_pBackNormalSprite->Init("back_dialog_select_map.png") ;
        m_pBackNormalSprite->setPosition(CCPointMake(512.0f, 304.0f)) ;
        m_pNormalLayer->addChild(m_pBackNormalSprite) ;
        
        CCSprite* pNormalClose = CCSprite::spriteWithFile("close.png") ;
        CCSprite* pSelectClose = CCSprite::spriteWithFile("close.png") ;
        pSelectClose->setColor(ccc3(1, 1, 1)) ;
        m_pButtonNormalClose = CCMenuItemImage::itemFromNormalSprite(pNormalClose, pSelectClose, this, menu_selector(CE7MenuLayer::ClickedNormalClose)) ;
        
        m_pButtonNormalLeft = CCMenuItemImage::itemFromNormalImage("button_left_n.png", "button_left_s.png", this,
                                                                   menu_selector(CE7MenuLayer::ClickedNormalLeft)) ;
        m_pButtonNormalRight = CCMenuItemImage::itemFromNormalImage("button_right_n.png", "button_right_s.png", this,
                                                                    menu_selector(CE7MenuLayer::ClickedNormalRight)) ;
        
        float offset_x = 512 ;
        
        m_pButtonNormalClose->setPosition(ccp(init_x-offset_x+485, init_y-50)) ;
        m_pButtonNormalLeft->setPosition(CCPointMake(init_x-165.0f+170.0f-offset_x, init_y-460.0f)) ;
        m_pButtonNormalRight->setPosition(CCPointMake(init_x+165.0f+170.0f-offset_x, init_y-460.0f)) ;
        
        m_pDialogNormalButtons = CCMenu::menuWithItems(m_pButtonNormalClose, m_pButtonNormalLeft, m_pButtonNormalRight, NULL) ;
        m_pNormalLayer->addChild(m_pDialogNormalButtons) ;
    }
    else // iphone.
    {
//        float init_x = 332 ;
//        float init_y = 254-80 ;
        float init_x = 332/2 - 15.0f ;
        float init_y = (254-80)/2+30 ;

        m_pBackNormalSprite = new CE7Sprite() ;
        m_pBackNormalSprite->Init("back_dialog_select_map_iphone.png") ;
        m_pBackNormalSprite->setPosition(CCPointMake(512.0f/2-30.0f, 304.0f/2)) ;
        m_pNormalLayer->addChild(m_pBackNormalSprite) ;
        
        CCSprite* pNormalClose = CCSprite::spriteWithFile("close_iphone.png") ;
        CCSprite* pSelectClose = CCSprite::spriteWithFile("close_iphone.png") ;
        pSelectClose->setColor(ccc3(1, 1, 1)) ;
        m_pButtonNormalClose = CCMenuItemImage::itemFromNormalSprite(pNormalClose, pSelectClose, this, menu_selector(CE7MenuLayer::ClickedNormalClose)) ;
        
        m_pButtonNormalLeft = CCMenuItemImage::itemFromNormalImage("button_left_n_iphone.png",
                                                                   "button_left_s_iphone.png", this,
                                                                   menu_selector(CE7MenuLayer::ClickedNormalLeft)) ;
        m_pButtonNormalRight = CCMenuItemImage::itemFromNormalImage("button_right_n_iphone.png",
                                                                    "button_right_s_iphone.png", this,
                                                                    menu_selector(CE7MenuLayer::ClickedNormalRight)) ;
        
        float offset_x = 240 ;
        
        m_pButtonNormalClose->setPosition(ccp(init_x-offset_x+485/2-15, init_y-50/2+3)) ;
        m_pButtonNormalLeft->setPosition(CCPointMake(init_x-offset_x+(170.0f-165.0f)/2-15.0f, init_y-460.0f/2+5.0f)) ;
        m_pButtonNormalRight->setPosition(CCPointMake(init_x-offset_x+(170.0f+165.0f)/2-15.0f, init_y-460.0f/2+5.0f)) ;
        
        m_pDialogNormalButtons = CCMenu::menuWithItems(m_pButtonNormalClose, m_pButtonNormalLeft, m_pButtonNormalRight, NULL) ;
        m_pNormalLayer->addChild(m_pDialogNormalButtons) ;
    }

    m_pButtonNormalBattle->setIsVisible(false) ;
    m_pButtonCustomBattle->setIsVisible(false) ;
    m_pActiveCustomSprite->setIsVisible(false) ;
    m_pNormalLayer->setIsVisible(true) ;

    InitStageSprite() ;
}

void CE7MenuLayer::StartNormalGame(int stage)
{
    s_pLogic->SetGameMode(0) ;
    s_pLogic->SetStageMap(stage) ;
    SetStep(LS_STOP) ;
}

void CE7MenuLayer::ClickedNormalClose()
{
    if (s_bPlaySound)
    {
        SimpleAudioEngine::sharedEngine()->playEffect(sound_button) ;
    }

    m_pNormalLayer->removeAllChildrenWithCleanup(false) ;
    m_pNormalLayer->setIsVisible(false) ;

    m_pButtonNormalBattle->setIsVisible(true) ;
    m_pButtonCustomBattle->setIsVisible(true) ;

    if (CE7StageData::GetStageData()->GetCompleteCount() < STAGE_COUNT)
    {
        m_pButtonCustomBattle->setIsEnabled(false) ;
        m_pActiveCustomSprite->setIsVisible(true) ;
    }
    else
    {
        m_pButtonCustomBattle->setIsEnabled(true) ;
        m_pActiveCustomSprite->setIsVisible(false) ;
    }
}

void CE7MenuLayer::ClickedNormalLeft()
{
    if (s_bPlaySound)
    {
        SimpleAudioEngine::sharedEngine()->playEffect(sound_button) ;
    }

    for (int i = m_nPageIndex*6; i < (m_nPageIndex+1)*6; ++i)
    {
        m_pStageRoot[i]->Hide() ;
    }

    --m_nPageIndex ;
    if (0 >= m_nPageIndex)
    {
        m_nPageIndex = 0 ;
    }

    for (int i = m_nPageIndex*6; i < (m_nPageIndex+1)*6; ++i)
    {
        m_pStageRoot[i]->Show() ;
    }
}

void CE7MenuLayer::ClickedNormalRight()
{
    if (s_bPlaySound)
    {
        SimpleAudioEngine::sharedEngine()->playEffect(sound_button) ;
    }

    for (int i = m_nPageIndex*6; i < (m_nPageIndex+1)*6; ++i)
    {
        m_pStageRoot[i]->Hide() ;
    }

    int max = STAGE_COUNT/6 - 1 ;
    ++m_nPageIndex ;
    if (max < m_nPageIndex)
    {
        m_nPageIndex = max ;
    }

    for (int i = m_nPageIndex*6; i < (m_nPageIndex+1)*6; ++i)
    {
        m_pStageRoot[i]->Show() ;
    }
}

void CE7MenuLayer::InitStageSprite()
{
    m_nPageIndex = 0 ;

    if (IsPad())
    {
        m_pStageNumberSheet = CCSpriteBatchNode::batchNodeWithFile("number_none.png") ;

        int w = 250/10 ;
        int h = 35 ;

        for (int i = 0; i < STAGE_COUNT; ++i)
        {
            m_pStageNormal[i] = CCSprite::spriteWithFile("button_stage_n.png") ;
            m_pStageSelect[i] = CCSprite::spriteWithFile("button_stage_s.png") ;
            m_pStageC[i] = CCSprite::spriteWithFile("button_stage_1.png") ;
            m_pStageL[i] = CCSprite::spriteWithFile("button_stage_2.png") ;
            m_pStageL[i]->setRotation(-40.0f) ;
            m_pStageR[i] = CCSprite::spriteWithFile("button_stage_2.png") ;
            m_pStageR[i]->setRotation(40.0f) ;
            
            CCSprite* pNumberF = CCSprite::spriteWithBatchNode(m_pStageNumberSheet, CCRectMake(w*((i+1)/10), 0, w, h)) ;
            CCSprite* pNumberS = CCSprite::spriteWithBatchNode(m_pStageNumberSheet, CCRectMake(w*((i+1)%10), 0, w, h)) ;
            
            m_pStageRoot[i] = new CE7TouchSprite(i, m_pStageNormal[i], m_pStageSelect[i], m_pStageC[i], m_pStageL[i], m_pStageR[i],
                                                 pNumberF, pNumberS, CE7StageData::GetStageData()->GetStageLevel(i), this) ;
            
            m_pStageRoot[i]->setPosition(CCPointMake(340 + (i%3)*170, 380 - ((i%6)/3)*180)) ;
            
            pNumberF->setPosition(CCPointMake(m_pStageRoot[i]->getPosition().x-w/2, m_pStageRoot[i]->getPosition().y)) ;
            pNumberF->setOpacity(150) ;
            pNumberS->setPosition(CCPointMake(m_pStageRoot[i]->getPosition().x+w/2, m_pStageRoot[i]->getPosition().y)) ;
            pNumberS->setOpacity(150) ;
            
            m_pNormalLayer->addChild(m_pStageRoot[i]) ;
            
            m_pStageNumberSheet->addChild(pNumberF) ;
            m_pStageNumberSheet->addChild(pNumberS) ;
        }
    }
    else
    {
        m_pStageNumberSheet = CCSpriteBatchNode::batchNodeWithFile("number_none_iphone.png") ;

        float w = 12.5f ;
        float h = 17.5f ;

        for (int i = 0; i < STAGE_COUNT; ++i)
        {
            m_pStageNormal[i] = CCSprite::spriteWithFile("button_stage_n_iphone.png") ;
            m_pStageSelect[i] = CCSprite::spriteWithFile("button_stage_s_iphone.png") ;
            m_pStageC[i] = CCSprite::spriteWithFile("button_stage_1_iphone.png") ;
            m_pStageL[i] = CCSprite::spriteWithFile("button_stage_2_iphone.png") ;
            m_pStageL[i]->setRotation(-40.0f) ;
            m_pStageR[i] = CCSprite::spriteWithFile("button_stage_2_iphone.png") ;
            m_pStageR[i]->setRotation(40.0f) ;

            CCSprite* pNumberF = CCSprite::spriteWithBatchNode(m_pStageNumberSheet, CCRectMake(w*((i+1)/10), 0, w, h)) ;
            CCSprite* pNumberS = CCSprite::spriteWithBatchNode(m_pStageNumberSheet, CCRectMake(w*((i+1)%10), 0, w, h)) ;
            
            m_pStageRoot[i] = new CE7TouchSprite(i, m_pStageNormal[i], m_pStageSelect[i], m_pStageC[i], m_pStageL[i], m_pStageR[i],
                                                 pNumberF, pNumberS, CE7StageData::GetStageData()->GetStageLevel(i), this) ;
            
            m_pStageRoot[i]->setPosition(CCPointMake((340+(i%3)*170)/2-30.0f, (380-((i%6)/3)*180)/2)) ;

            pNumberF->setPosition(CCPointMake(m_pStageRoot[i]->getPosition().x-w/2, m_pStageRoot[i]->getPosition().y)) ;
            pNumberF->setOpacity(150) ;
            pNumberS->setPosition(CCPointMake(m_pStageRoot[i]->getPosition().x+w/2, m_pStageRoot[i]->getPosition().y)) ;
            pNumberS->setOpacity(150) ;
            
            m_pNormalLayer->addChild(m_pStageRoot[i]) ;
            
            m_pStageNumberSheet->addChild(pNumberF) ;
            m_pStageNumberSheet->addChild(pNumberS) ;
        }
    }

    for (int i = 0; i < 6; ++i)
    {
        m_pStageRoot[i]->Show() ;
    }

    m_pNormalLayer->setIsRelativeAnchorPoint(true) ;
    m_pNormalLayer->setAnchorPoint(CCPointMake(0.5f, 1.0f)) ;
    m_pNormalLayer->addChild(m_pStageNumberSheet) ;

}


















